package cfgs.sumaresta.vistas;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;


@SuppressWarnings("serial")
public class Conversor extends JPanel implements ActionListener { 
	private JLabel lbeuro;
	private JLabel lbdolar;
	private JButton btnconvertir;
	private JButton btnborrar;
	private JTextField caja1;
	private JTextField caja2;
	
	public Conversor() {
		this.setLayout(null);
		this.setSize(500, 400);
		
		lbeuro = new JLabel("EUR");
		lbeuro.setBounds(50, 50, 300, 20);
		this.add(lbeuro);
		
		caja1 = new JTextField();
		caja1.setBounds(150, 50, 100, 20);
		this.add(caja1);
		
		lbdolar = new JLabel("USD");
		lbdolar.setBounds(50, 150, 100, 20);
		this.add(lbdolar);
		
		caja2 = new JTextField();
		caja2.setBounds(150, 150, 100, 20);
		this.add(caja2);
		
		btnconvertir = new JButton("Convertir");
		btnconvertir.setBounds(50, 250, 100, 20);
		this.add(btnconvertir);
		btnconvertir.addActionListener(this);
		
		btnborrar = new JButton("Borrar");
		btnborrar.setBounds(300, 250, 100, 20);
		this.add(btnborrar);
		btnborrar.addActionListener(this);
		
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource()==btnconvertir) {
			double num1 = Double.valueOf(caja1.getText());
			double num2 = num1*1.29647;
			caja2.setText(String.valueOf(num2));
		}
		
				
		if (e.getSource()==btnborrar) {
			caja1.setText(null);
			caja2.setText(null);
		}
		
	}
	

}
